package com.common.db;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.common.PropertiesUtils;

import java.sql.SQLException;
import java.util.Properties;

public class DbPoolConnection_lims {
    public static String dbString = "config_test/db_lims.properties";
    private static DbPoolConnection_lims databasePool = null;
    private static DruidDataSource dds = null;
    static {
        Properties properties = PropertiesUtils.loadPropertyFile(dbString);
        try {
            dds = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private DbPoolConnection_lims() {
    }

    public static synchronized DbPoolConnection_lims getInstance() {
        if (null == databasePool) {
            databasePool = new DbPoolConnection_lims();
        }
        return databasePool;
    }

    public static DruidPooledConnection getConnection() throws SQLException {
        return dds.getConnection();
    }

    public DruidDataSource getDataSource() throws SQLException {
        return dds;
    }
}
